#ifndef BSONOBJEDITORDELEGATE_H
#define BSONOBJEDITORDELEGATE_H

#include <QObject>
#include <QLineEdit>
#include <QItemDelegate>
class UserIDDelegate : public QItemDelegate
{
      Q_OBJECT
  public:
      UserIDDelegate(QObject *parent = 0): QItemDelegate(parent) { }
      QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
          const QModelIndex &index) const
      {
          QLineEdit *editor = new QLineEdit(parent);
//          QRegExp regExp("[0-9]{0,10}");
//          editor->setValidator(new QRegExpValidator(regExp, parent));
          return editor;
      }
      void setEditorData(QWidget *editor, const QModelIndex &index) const
      {
          QString text = index.model()->data(index, Qt::EditRole).toString();
          QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
          lineEdit->setText(text);
      }
      void setModelData(QWidget *editor, QAbstractItemModel *model,
          const QModelIndex &index) const
      {
          QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
          QString text = lineEdit->text();
          model->setData(index, text, Qt::EditRole);
      }
      void updateEditorGeometry(QWidget *editor,
          const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
          editor->setGeometry(option.rect);
      }
  };

class BSONObjEditorDelegate : public QItemDelegate
{
     Q_OBJECT
public:
    BSONObjEditorDelegate(int durationColumn, QObject *parent=0);


    void paint(QPainter *painter, const QStyleOptionViewItem &option,
               const QModelIndex &index) const;
    QWidget *createEditor(QWidget *parent,
                          const QStyleOptionViewItem &option,
                          const QModelIndex &index) const;
    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model,
                      const QModelIndex &index) const;

private slots:
    void commitAndCloseEditor();

private:
    int durationColumn;
};

#endif // BSONOBJEDITORDELEGATE_H
